<template>
  <!-- 关联直播 （pc端无搜索功能）-->
  <div>
    <div class="aboutlives" v-if="hasRoot">
      <div class="title">直播列表</div>
      <div class="ld_search_date">
        <radio_group :radio_values="['近7天', '30天', '90天']" v-model="KindName" class="tab01" />
      </div>
      <!-- 搜索框 -->
      <div class="searchBox">
        <input
          type="text"
          v-model.trim="keyword"
          placeholder="请输入直播标题或关键词搜索"
          @keyup.enter="toSearch"
        />
        <img src="@/assets/one/seach.png" v-if="!imgBox" @click="toSearch" />
        <img src="@/assets/two/search.png" v-if="imgBox" @click="toSearch" />
      </div>
      <!-- 直播列表 -->
      <div
        class="livesbox"
        v-for="(item, index) in proList"
        :key="'a' + index"
        @click="gotolives(item.authorId, item.roomId)"
      >
        <div class="head">
          <div class="img">
            <img :src="item.roomLogo?item.roomLogo:''" v-errorImg:live />
          </div>
          <div>
            <h3>{{ item.roomTitle }}</h3>
            <p>开播时间: {{ item.beginTime }}</p>
          </div>
        </div>
        <div class="livedata">
          <div>
            <span>
              {{
              format_time((item.endUnix - item.beginUnix) * 1000)
              }}
            </span>直播时长
          </div>
          <div>
            <span>{{ format_num(item.liveproduct) }}</span>商品数
          </div>
          <div>
            <span>{{ format_num(item.livevolume) }}</span>直播销量
          </div>
          <div>
            <span>{{ format_num(item.livesales) }}</span>直播销售额
          </div>
        </div>
      </div>
      <!-- 查看更多 -->
      <div class="more" @click="addcount" v-if="!isOver && proList.length != 0 && !loading">查看更多</div>
      <div
        class="tld_details"
        v-if="isOver && proList.length && !loading"
      >已经到底了哟，电脑登录dy.zsjx114.com查看更多详细数据~</div>
      <div v-if="loading" style="margin-top: 1rem;">
        <van-loading class="loading" v-if="loading" type="spinner" :vertical="true" />
      </div>
      <!-- 暂无数据 -->
      <div class="zanwu" v-if="proList.length == 0 && !loading">
        <img src="@/assets/three/noData.png" />
        <p>暂无数据</p>
      </div>
    </div>
    <noPower :minLeve="$store.state.userRoot[88][90].ownerMinLevel" v-else />
    <!-- 分割线 -->
    <div class="line"></div>
  </div>
</template>
<script>
import radio_group from './component/radio_group.vue';
export default {
  components: { radio_group },
  data() {
    return {
      keyword: '',
      KindName: '30天',
      searchDates: [], //存放开始时间和结束时间
      imgBox: false,
      proList: [], //直播列表
      count: 0, // 直播列表长度
      page: 1,
      isOver: false,
      loading: false,
      hasRoot: true
    };
  },
  watch: {
    // 搜索
    keyword: function (newVal, oldVal) {
      if (newVal == '') {
        this.imgBox = false;
        this.proList = [];
        this.page = 1;
        this.isOver = false;
        this.getdata();
      } else {
        this.keyword = newVal;
        this.imgBox = true;
      }
    },
    KindName: function (newVal, oldVal) {
      if (this.KindName != '') {
        this.KindName = newVal;
        this.page = 1;
        this.proList = [];
        this.getTime();
        this.getdata();
      }
    }
  },
  created() {
    this.getTime(); //时间
    this.getdata();
  },
  methods: {
    //   搜索
    toSearch() {
      this.proList = [];
      this.page = 1;
      this.loading = true;
      this.getdata();
    },
    // 获取时间
    getTime() {
      switch (this.KindName) {
        case '近7天':
          this.endDate = this.timestamp(Date.now() / 1000 - 1 * 86400, 'Y-M-D');
          this.startDate = this.timestamp(Date.now() / 1000 - 86400 * 7, 'Y-M-D');
          break;
        case '30天':
          this.endDate = this.timestamp(Date.now() / 1000 - 86400 * 1, 'Y-M-D');
          this.startDate = this.timestamp(Date.now() / 1000 - 86400 * 30, 'Y-M-D');
          break;
        case '90天':
          this.endDate = this.timestamp(Date.now() / 1000 - 86400 * 1, 'Y-M-D');
          this.startDate = this.timestamp(Date.now() / 1000 - 86400 * 90, 'Y-M-D');
          break;
        default:
          this.startDate = this.liveTime[0];
          this.endDate = this.liveTime[1];
          break;
      }
      this.liveTime = [this.startDate, this.endDate];
    },
    getdata() {
      this.loading = true;
      this.$axios
        // .post('/api/brand/Live', {
        .post('/api/Brand/BrandRelLive', {
          brandId: this.$route.query.id,
          startdate: this.startDate,
          enddate: this.endDate,
          order_by: '0',
          page: this.page,
          size: 30,
          sort: 0,
          KeyWord: this.keyword
        })
        .then(res => {
          if (res.data.code == 0) {
            this.loading = false;
            if(res.data.data.livelist){
              this.proList = this.proList.concat(res.data.data.livelist);
              this.count = res.data.count;
              this.isOver = res.data.data.livelist.length < 10;
            }else{
              this.isOver = true;
            }
          }
          if (res.data.code == 1003) {
            this.hasRoot = false;
          }
        });
    },
    // 查看更多
    addcount() {
      this.page = this.page + 1;
      this.getdata();
    },
    // 跳转直播详情
    gotolives(author_id, room_id) {
      this.$router.push({
        path: '/LiveForDetailsMain',
        query: { author_id, room_id }
      });
    }
  }
};
</script>
<style lang="less" scoped>
.tld_details {
  font-size: 0.32rem;
  color: #b5b5b5;
  margin-top: 0.4rem;
  text-align: center;
}
// tab日期切换
.ld_search_date {
  margin-top: 0.4rem;
  font-size: 0;
  span {
    display: inline-block;
    padding: 0.08rem 0.186667rem;
    background-color: #fff;
    border-radius: 4px;
    border: solid 1px #e5e5e5;
    font-size: 0.32rem;
    margin-right: 0.2rem;
    &.active {
      background-color: #fd7f2c;
      border-color: #fd7f2c;
      color: #fff;
    }
  }
}
.aboutlives {
  width: 9.2rem;
  margin: 0 auto;
  padding-bottom: 0.666667rem;
}
.title {
  position: relative;
  padding-left: 0.266667rem;
  font-size: 0.4rem;
  color: #222;
  margin-top: 0.6933rem;
  &:before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.1rem;
    display: inline-block;
    width: 0.08rem;
    height: 0.373333rem;
    background-color: #fd7f2c;
    border-radius: 3px;
  }
}
// 搜索框
/* 搜索框 */
.searchBox {
  display: flex;
  align-items: center;
  box-sizing: border-box;
  border-radius: 0.1333rem;
  border: solid 1px #e5e5e5;
  width: 9.2rem;
  height: 0.986667rem;
  padding-left: 0.5rem;
  margin-top: 0.2666rem;
  input[type='text'] {
    width: 86%;
    height: 100%;
    border: none;
    font-size: 0.3733rem;
    color: #222;
  }
  input {
    //处理ios兼容性(阴影)
    -webkit-appearance: none;
  }
  img {
    width: 0.4rem;
    height: 0.4rem;
    margin-left: 0.4rem;
  }
}
// 直播列表
.livesbox {
  padding-top: 0.4rem;
  border-bottom: 1px solid #e5e5e5;
  .head {
    display: flex;
    .img {
      width: 1.333333rem;
      height: 1.333333rem;
      img {
        width: 100%;
        height: 100%;
        border-radius: 0.2666rem;
        border: 1px solid #e5e5e5;
        object-fit: cover;
      }
    }
    div {
      margin-right: 0.26666rem;
      h3 {
        width: 6.666rem;
        font-size: 0.4rem;
        color: #222;
        font-weight: normal;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        padding-top: 0.1333rem;
        padding-bottom: 0.1rem;
      }
      p {
        font-size: 0.32rem;
        color: #888;
      }
    }
  }
  .livedata {
    display: flex;
    justify-content: space-around;
    padding-top: 0.3466rem;
    div {
      span {
        display: block;
        font-family: DINPro-Medium;
        font-size: 0.4rem;
        color: #222;
      }
      font-size: 0.32rem;
      color: #888;
      text-align: center;
      padding-bottom: 0.4rem;
    }
  }
}
//   查看更多
.more {
  margin: 0.6667rem auto 0 auto;
  width: 2.1333rem;
  height: 0.8rem;
  line-height: 0.8rem;
  border-radius: 0.1333rem;
  border: solid 1px #fd7f2c;
  font-size: 0.3467rem;
  color: #fd7f2c;
  text-align: center;
}
//   暂无数据
.zanwu {
  width: 5.3333rem;
  height: 4rem;
  margin: 1rem auto 0 auto;
  img {
    margin: 0 auto;
    width: 4rem;
    height: 3.2rem;
    display: block;
  }
  p {
    font-size: 0.3467rem;
    line-height: 0.4rem;
    color: #888;
    text-align: center;
  }
}
// 分割线
.line {
  width: 100%;
  height: 0.1866rem;
  background: #f1f1f1;
}
</style>
